class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size();
        if (n == 0)
        {
            return 0;
        }
        vector<int> v(n + 1, 0);
        for (int i = 1; i <= n; i++)
        {
            v[i] = v[i - 1] + nums[i - 1];
        }
        int ans = INT_MAX;
        for (int i = 1; i <= n; i++)
        {
            int tmp = target + v[i - 1];
            auto bound = lower_bound(v.begin(), v.end(), tmp);
            if (bound != v.end())
            {
                ans = min(ans, static_cast<int>(bound - v.begin() - (i - 1)));
            }
        }
        return ans == INT_MAX ? 0 : ans;
    }
};